home *** CD-ROM | disk | FTP | other *** search
- Path: engnews1.Eng.Sun.COM!taumet!clamage
- From: clamage@Eng.sun.com (Steve Clamage)
- Newsgroups: comp.std.c++
- Subject: Re: 'const' in header files
- Date: 28 Feb 1996 20:46:08 GMT
- Organization: Sun Microsystems Inc.
- Approved: clamage@eng.sun.com (comp.std.c++)
- Message-ID: <4h2bud$l69@engnews1.Eng.Sun.COM>
- References: <AD5A0C5196681CA0D@sleipner.nts.mh.se>
- Reply-To: clamage@Eng.sun.com
- NNTP-Posting-Host: taumet.eng.sun.com
- Content-Type: text
- X-Nntp-Posting-Host: taumet.eng.sun.com
- Content-Length: 2300
- X-Lines: 43
- Originator: clamage@taumet
-
- In article AD5A0C5196681CA0D@sleipner.nts.mh.se, lars.farm@nts.mh.se (Lars Farm) writes:
- >This is a reply to a thread in c.l.c++.moderated. The moderator asked me to
- >post this in com.std.c++ instead. The thread started with someone
- >complaining about a warning for an unused variable where he had const float
- >x = y; in a header.
- >
- >Experts explained that this is as it should be for const float, but not for
- >const int (I know that the std does not talk about warnings). The point is:
- >The experts seems to find some kind of conceptual difference between named
- >constant floats and named constant ints, such that declaring const int K =
- >L; in a header is considered good practice but const float X = Y; in a
- >header is not and justifies a warning. I don't think there should be any
- >such difference.
-
- I was one of the people who posted articles on that thread, and I
- certainly never said there was or should be any conceptual difference.
- I did say the compiler is allowed to treat them differently.
-
- AS AN OPTIMIZATION, a non-extern const does not always need to be
- instantiated. No compiler is required to make that optimization, to
- document whether it makes that optimization, or even to be consistent
- about such optimizations. That is the whole point of optimizations:
- no portable and standard-conforming program can tell the difference.
- You have to resort to things like examining the executable image, or
- performing a timing analysis, or some other technique outside the
- language definition.
-
- Why do I say this is an optimization? The standard doesn't (and
- shouldn't, in my view) say explicitly that it is sometimes ok to omit
- the instantiation. Instead, it says what the results of certain
- operations must be. It turns out that no valid program can detect
- that a const was omitted. Any valid test the program makes will report
- that the constant was instantiated. The compiler can choose to omit
- the instantiation only if you don't try to find out that it did.
- (Shroedinger, anyone?)
-
- If you are unhappy about your compiler generating unncessary code or
- data, or warning about things which you think are the compiler's own
- fault, you should take that up with the vendor. In this particular
- case, no language rule is being violated.
-
- ---
- Steve Clamage, stephen.clamage@eng.sun.com
-
-
-
-
- [ comp.std.c++ is moderated. To submit articles: Try just posting with your
- newsreader. If that fails, use mailto:std-c++@ncar.ucar.edu
- comp.std.c++ FAQ: http://reality.sgi.com/austern/std-c++/faq.html
- Moderation policy: http://reality.sgi.com/austern/std-c++/policy.html
- Comments? mailto:std-c++-request@ncar.ucar.edu
- ]
-